package com.mdd.admin.controller.yylq;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.yylq.ITAppPublicWelfareProjectService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.yylq.TAppPublicWelfareProjectCreateValidate;
import com.mdd.admin.validate.yylq.TAppPublicWelfareProjectSearchValidate;
import com.mdd.admin.validate.yylq.TAppPublicWelfareProjectUpdateValidate;
import com.mdd.admin.vo.yylq.TAppPublicWelfareProjectDetailVo;
import com.mdd.admin.vo.yylq.TAppPublicWelfareProjectListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/adminapi/yylq/publicWelfareProject")
@Api(tags = "羊羊领企---领企公益管理")
public class TAppPublicWelfareProjectController {

    @Resource
    ITAppPublicWelfareProjectService iTAppPublicWelfareProjectService;

    @GetMapping("/list")
    @ApiOperation(value="领企公益列表")
    public AjaxResult<PageResult<TAppPublicWelfareProjectListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated TAppPublicWelfareProjectSearchValidate searchValidate) {
        PageResult<TAppPublicWelfareProjectListedVo> list = iTAppPublicWelfareProjectService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="领企公益详情")
    public AjaxResult<TAppPublicWelfareProjectDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TAppPublicWelfareProjectDetailVo detail = iTAppPublicWelfareProjectService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "领企公益新增")
    @PostMapping("/add")
    @ApiOperation(value="领企公益新增")
    public AjaxResult<Object> add(@Validated @RequestBody TAppPublicWelfareProjectCreateValidate createValidate) {
        iTAppPublicWelfareProjectService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "领企公益编辑")
    @PostMapping("/edit")
    @ApiOperation(value="领企公益编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TAppPublicWelfareProjectUpdateValidate updateValidate) {
        iTAppPublicWelfareProjectService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "领企公益删除")
    @PostMapping("/del")
    @ApiOperation(value="领企公益删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTAppPublicWelfareProjectService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
